set RECV_LISTEN(NOTICE) m_notice

proc m_notice {chid raw parent me} {
	global CHANS_$chid
	set user ""
	set host ""

	regexp {:([^!]+)!([^@]+)@([^ ]+) NOTICE ([^ ]+) :(.+)} $raw -> \
		nick user host to msg
	regexp {:([^!]+) NOTICE ([^ ]+) :(.+)} $raw -> nick to msg
	
	if { "$to" == "$me" } {
		if [regexp {\001VERSION ([^\001]+)\001} $msg -> versionreply] {
			infomsg $parent.console "CTCP VERSION [tr {reply from}] $nick: $versionreply\n"
		} elseif [regexp {\001SOURCE ([^\001]+)\001} $msg -> srcreply] {
			infomsg $parent.console "CTCP SOURCE [tr {reply from}] $nick: $srcreply\n"
		} elseif [regexp {\001TIME ([^\001]+)\001} $msg -> timereply] {
			infomsg $parent.console "CTCP TIME [tr {reply from}] $nick: $timereply\n"
		} elseif [regexp {\001([^ ]+) ([^\001]+)\001} $msg -> type reply] {
			infomsg $parent.console "[tr {Unknown CTCP reply}] ($type) [tr from] $nick: $reply\n"
		} else {
			notice $parent.console "*$nick* $msg\n"
		}
	} else {
		if { [string tolower $to] == "auth" } {
			notice $parent.console "\[SERVER\] $msg\n"
		} else {
			set currservertab $n_conns.$chid
			set channel [$currservertab tab [$currservertab select] -text]	
			set out "console"
			if { $channel != [tr "Console"] } {
				set num [set "CHANS_$chid\([string tolower $channel]\)"]
				set out "chan$num"
			}
			notice $parent.$out "*$nick* $msg\n"
		}
	}
}
